Installation

To install:

  1. Download Miniforge3 from the miniforge github and install it with the recommended settings.
  2. Open "Miniforge Prompt". On Windows: Press "Start" and type "Miniforge Prompt"
  3. Run the following command in the Miniforge Prompt:

conda create -n hydrolib-core-dsd -y python=3.12

  1. When this has finished succesfully, run

conda activate hydrolib-core-dsd

  1. Once in the active enviroment we install all dependencies with pip:

pip install hydrolib-core geopandas openpyxl notebook ipykernel

Exercises HYDROLIB-core

We have set up a Jupyter Notebook with exercises to get you started on how to use HYDROLIB-core for creating models.

  1. In the active environment install a jupyter kernel:

python -m ipykernel install --name=hydrolib-core-dsd

  1. And start the notebook:

jupyter notebook <path to magdalena_workbook_exercises.ipynb>

In this tutorial we will create a 1D2D fluvial flood model of the Magdalena river in Columbia.

Worked out answers

An example of the worked out exercises can be found within the other provided notebook: magdalena_workbook_workedout.ipynb.

Cheat sheet

In HYDROLIB-core, there is a class called FileModel, which is used to represent an individual kernel file. This class has multiple derived implementations, with each one corresponding to a specific kernel file. Every FileModel, except for the root model, is referenced within another FileModel, following the same hierarchy as the kernel files themselves.

The table below contains the models relevant for today's exercises.

Kernel files vs HYDROLIB-core FileModels

Kernel file FileModel File reference
Model definition file (*.mdu) FMModel -
Network file (*_net.nc) NetworkModel MDU > [geometry] > netFile
Cross-section location file (crosloc.ini) CrossLocModel MDU > [geometry] > crossLocFile
Cross-section definition file (crosdef.ini) CrossDefModel MDU > [geometry] > crossDefFile
Roughness file (roughness-*.ini) FrictionModel MDU > [geometry] > frictFile
New external forcing file (*_bnd.ext) ExtModel MDU > [external forcing] > extForceFileNew
Boundary conditions file (*.bc) ForcingModel New external forcing file > [boundary] > forcingFile
1D initial conditions field file (*.ini) OneDFieldModel Initial field file > [initial] > dataFile
Initial field file (*.ini) IniFieldModel MDU > [geometry] > iniFieldFile
Structures file (structures.ini) StructureModel MDU > [geometry] > structureFile

Commonly used functions of a FileModel

Each FileModel offers a set of commonly used functions.


init(): Create a new file model instance

Parameters (all optional):

Example:

fmmodel = FMModel(filepath='dflowfm.mdu', recurse=True)

The above line creates an FM model object with all the data from the dflowfm.mdu MDU file. Because recurse=True it also loads all data from the other model files, such as the cross sections.


save(): Write the model data to a file

Parameters (all optional):

Example:

fmmodel.save(filepath='dflowfm_saved.mdu', recurse=True)

The above line saves the FM model data to the dflowfm_saved.mdu MDU file. Because recurse=True it also writes the model data to the other model files, such as the cross sections files.


show_tree(): Print the file model tree

fmmodel.show_tree()